<template>
	<view>
		<view class="container">
			<view class="border_box">
				<textarea name="" :maxlength="1000" v-model="content" placeholder="请输入文字.." class="textarea_style" id=""
					cols="30" rows="10"></textarea>
				<view class="most_count">
					最多{{content.length}}/1000字
				</view>
				<view class="img_list">
					<view class="image_box" @tap="add_img">
						<image src="/static/time_line/add_img.png" mode="widthFix" class="img_add"></image>
					</view>
					<view class="image_box" v-for="item,id in img_url" :key="id">
						<image src="/static/time_line/del_btn.png" @tap="del_img(id)" mode="widthFix" class="del_btn">
						</image>
						<image :src="item" mode="aspectFill" class="img_add"></image>
					</view>

				</view>
			</view>
		</view>
		<view class="bottom_box">

			<view class="submit_btn" @click="release()">
				<text>
					立即发布
				</text>
			</view>
		</view>
	</view>
</template>
<style>

</style>
<script>
	export default {
		data() {
			return {
				content: '',
				img_url: []
			}
		},
		methods: {
			add_img: function() {
				this.$api.uploadImage(9, res => {
					if (res.status) {
						this.img_url.push(res.data.url);
					}
				})
			},
			del_img: function(id) {
				this.img_url.splice(id, 1)
			},
			release: function() {
				if (this.content == '') {
					this.$common.errorToShow('请输入内容')
					return;
				}
				let data = {
					content: this.content,
					images: this.img_url
				}
				uni.showModal({
					content: '确定发布吗?',
					success: (res) => {
						if (res.confirm) {
							this.$api.release(data, res => {
								if (res.status) {
									this.$common.successToShow(res.msg, () => {
										uni.navigateBack()
									})
								} else {
									this.$common.errorToShow(res.msg)
								}
							})
						}
					}
				});
			}
		}
	}
</script>
<style lang="scss">
	.border_box {
		width: 100%;
		background: #292B2B;
		box-shadow: 0px 5rpx 30rpx 1rpx rgba(0, 0, 0, 0.05);
		border-radius: 20rpx;
		padding: 20rpx;

		.img_list {
			width: 100%;
			padding-top: 40rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			flex-wrap: wrap;

			.image_box {
				width: 190rpx;
				height: 190rpx;
				margin-bottom: 30rpx;
				position: relative;

				.img_add {
					width: 190rpx;
					height: 190rpx;
					position: relative;
					border-radius: 20rpx;
				}

				.del_btn {
					position: absolute;
					top: 20rpx;
					right: 20rpx;
					width: 35rpx;
					height: 35rpx;
					z-index: 10;
				}
			}


		}

		.img_list::after {
			content: '';
			width: 190rpx;
		}

		.most_count {
			text-align: right;
			font-size: 28rpx;
			color: #A4A4A4;
			width: 100%;
		}

		.textarea_style {
			width: 100%;
			height: 235rpx;
			color: #e5e5e5;
			font-size: 28rpx;
			line-height: 40rpx;
			box-sizing: border-box;
		}
	}

	.container {
		width: 100%;
		padding: 45rpx;
	}

	page {
		background-color: #101010;
	}
</style>
